# !/usr/bin/env python
# -*- coding:utf-8 -*-
# project name: CP_Automation
# author: "SongFang" 
# creation time: 2018/7/4 16:15
# Email: geg726@163.com

import unittest
from Operation.element import Element
from selenium.webdriver.common.keys import Keys
import time

el = Element()

def login(phone,passwd):
    #删除手机号
    el.xpath('//*[@id="app"]/div/div/content/div[2]/div[1]/input').clear()
    el.xpath('//*[@id="app"]/div/div/content/div[2]/div[1]/input').send_keys(Keys.CONTROL + 'a')
    el.xpath('//*[@id="app"]/div/div/content/div[2]/div[1]/input').send_keys(Keys.BACKSPACE)

    #删除密码
    el.xpath('//*[@id="app"]/div/div/content/div[2]/div[2]/input').clear()
    el.xpath('//*[@id="app"]/div/div/content/div[2]/div[2]/input').send_keys(Keys.CONTROL + 'a')
    el.xpath('//*[@id="app"]/div/div/content/div[2]/div[2]/input').send_keys(Keys.BACKSPACE)

    #手机号和密码封装

    el.xpath('//*[@id="app"]/div/div/content/div[2]/div[1]/input').send_keys(phone)
    el.xpath('//*[@id="app"]/div/div/content/div[2]/div[2]/input').send_keys(passwd)

class Test(unittest.TestCase):
    """火狐浏览器H5测试"""

    @classmethod
    def setUpClass(cls):
        cls.driver = el.Driver()
        el.openurl("http://192.168.1.190/mayi-h5/index.html#/home/my")
        el.xpath("//span[text()='点击登录']").send_keys(Keys.F12)
        el.xpath("//span[text()='点击登录']").send_keys(Keys.CONTROL, Keys.SHIFT, 'm')
        el.xpath("//span[text()='点击登录']").click()

    def test01(self):
        """H5手机号登录-手机号错误"""
        el.xpath("//span[text()='手机号登录']").click()
        login('135302611033','123456')
        self.assertFalse(el.trywait_assert_xpath("//span[text()='投注记录']"), '登录失败')

    def test02(self):
        """H5手机号登录-密码错误"""
        login('13530261103','1234564')
        self.assertFalse(el.trywait_assert_xpath("//span[text()='投注记录']"), '登录失败')

    def test03(self):
        """H5手机号登录-不存在的手机号"""
        login('11211111111','123456')
        self.assertFalse(el.trywait_assert_xpath("//span[text()='投注记录']"), '登录失败')

    def test04(self):
        """H5手机号登录"""
        login('13530261103','123456')
        self.assertFalse(el.trywait_assert_xpath("//span[text()='投注记录']"), '登录失败')

    @classmethod
    def tearDownClass(cls):
        cls.driver.quit()